<?php
/**
 * @Author: Marte
 * @Date:   2017-08-13 20:51:16
 * @Last Modified by:   Marte
 * @Last Modified time: 2017-08-17 21:44:39
 */
// $_sql='select headicon,nickname,introduce,rank,zan,comment from userregisters';
// $_result=$_mysql->query($_sql);//返回结果集合
if(isset($_GET['page']))
{
  $_page=$_GET['page'];
  if(empty($_page)||$_page<=0||!is_numeric($_page))
  {
     $_page=1;
  }
  else
  {
    $_page=intval($_page);//取整
  }
}
else
{
  $_page=1;
}

$_pagesize=8;//每页有几条
$_pagenum=($_page-1)*$_pagesize;//每页第一个
mysqli_query($_mysql,"SELECT id FROM userregisters");
// echo;
$_pagesnum=ceil(mysqli_affected_rows($_mysql)/$_pagesize);//共有几页
//如果$_page>总页数
if($_page>$_pagesnum)
{
  $_page=$_pagesnum;
}
$_result=$_mysql->query("select * from userregisters  order by id desc limit $_pagenum,$_pagesize;");

?>
<span class="friend_title">全部书友</span>
<div class="friend_main">
    <ul class="start">
        <?php
            while($_assoc=$_result->fetch_assoc())
            {
              $idd=$_assoc['id'];
              //获取该成员的username，与comment中的receive想通，统计影响的行数
              // include 'common/sum_comment.func.php';//引入函数
             $receive=$_assoc['username'];
            $sql='select id from comment where receive="'.$receive.'"';
        $_mysql->query($sql);

        $_num=mysqli_affected_rows($_mysql);

        $sql1="update userregisters set comment='$_num' where username='$receive'";
        $_mysql->query($sql1);
        ?>
        <li>
            <i><img src="<?php echo $_assoc['headicon'] ?>" alt=""></i>
            <div class="friend_main_right">
                <span class="username"><?php echo $_assoc['nickname'] ?></span><em><img src="images/isgui.png" alt=""></em>
                <p><?php echo $_assoc['introduce'] ?></p>

                <span class="bottom_s label"><?php echo $_assoc['rank'] ?></span>
                <span class="bottom_s not_label1"><a href="" name="message" title="<?php echo $_assoc['id'] ?>"><?php echo $_assoc['comment'] ?>条评论</a></span>
                <span class="bottom_s not_label2"><a href="" title=""><?php echo $_assoc['zan'] ?>人点赞</a></span>
                <?php
                $sqll='select id from follow where active="'.$_SESSION['username'].'" and passive="'.$_assoc['username'].'"';
                 $_mysql->query($sqll);


                    if(mysqli_affected_rows($_mysql))
                    {
                       echo "<span class='bottom_s not_label3 yiguanzhu'><a href=''>已关注</a></span>";
                    }else{

                      echo "<span class='bottom_s not_label3'><a href='data/user/add_follow.php?action=".$_assoc['username']."' >关注</a></span>";
                    }
                ?>

            </div>
            <div class="clear">

            </div>
        </li>
        <?php

            }
        ?>


    </ul>
     <div class="clear">

    </div>
    <ul class="end">
     <?php
                for($i=0;$i<$_pagesnum;$i++)
                {
                  echo '<li><a href="person.php?change=4&page='.($i+1).'">'.($i+1).'</a></li>';
                }
                echo '<li><a href="person.php?change=4&page='.($_page+1).'" >></a></li>';
            ?>
   <!--      <li><a href="" title="">1</a></li> -->
    </ul>
</div>




















